import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../base/base_state.dart';
import '../../components/LoginTextField.dart';
import '../../components/LoginTextFieldColor.dart';
import '../../resources.dart';

import 'model/change_phone_model.dart';

/// created by hcl
/// on 2024/2/27
/// ChangePhonePage
/// desc
class ChangePhonePage extends StatefulWidget {
  const ChangePhonePage({super.key});

  @override
  State<StatefulWidget> createState() => _ChangePhoneState();
}

class _ChangePhoneState extends BaseState<ChangePhoneModel, ChangePhonePage> {
  @override
  String get title => word.mine_phone;

  @override
  ChangePhoneModel initModel() {
    return ChangePhoneModel();
  }

  @override
  Widget bodyWidget(BuildContext context) {
    return Consumer<ChangePhoneModel>(
        builder: (BuildContext context, model, Widget? child) {
      return Container(
        padding: EdgeInsets.only(top: 30.ss, bottom: 12.ss, left: 13.5.ss, right: 13.5.ss),
        child: Column(
          children: [
            LoginTextFieldColor(
              model.phoneController,
              model.phoneFocusNode,
              word.please_phone_new,
              keyboardType: TextInputType.number,
            ),
            SizedBox(height: 27.ss),
            LoginTextFieldColor(model.codeController, model.codeFocusNode,
                word.please_enter_code,
                keyboardType: TextInputType.text,
                maxLength: 6,
                rightImage: commonGetCode(
                  () {
                    hideKeyboard();
                    model.getCode();
                  },
                  model.currentTime > 0
                      ? '${model.currentTime}S'
                      : word.get_code,
                ),
                rightWidth: 120.ss),
            const Spacer(),
            commonButton(() {
              hideKeyboard();
              model.checkCode();
            }, word.submit),
          ],
        ),
      );
    });
  }
}
